<template>
	<view>

		<view class="none_box">
			<image src="/static/user/area_img.png" mode="widthFix" class="none_img"></image>
			<view class="none_text" v-if="!userInfo.area_type">
				尚未加入任何疆域
			</view>
			<view class="none_text" v-else>
				恭喜您，您已加入<text style="color:#f00">{{userInfo.area_type_name}}疆域</text>
			</view>
		</view>

		<view class="bottom_box">
			<view class="submit_btn" @click="add()" v-if="!userInfo.area_type">
				立即加入
			</view>
			<view class="submit_btn" @click="back()" v-else>
				返回
			</view>
		</view>
		<uni-popup ref="choose_area" type="center">

			<view class="area_box">
				<view class="title">
					选择疆域
				</view>
				<view class="area_list">
					<view class="area_item" :class="{area_on:id == choose_id}" v-for="item,id in list" :key="id"
						@tap="choose(id)">
						<view>

							{{item.name}}
						</view>
					</view>

				</view>
			</view>
			<view class="confirm_btn" @tap="on_confirm">
				确定
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				choose_id: '',

				userInfo: {}
			}
		},
		onLoad() {
			let data = {}
			this.$api.getAreaList2(data, res => {
				if (res.status) {
					this.list = res.data;
				}
			})

			this.$api.userInfo({}, res => {
				if (res.status) {
					this.userInfo = res.data;
				}
			})
		},
		methods: {
			back: function() {
				uni.navigateBack()
			},


			add: function() {
				this.$refs.choose_area.open()
			},
			choose: function(id) {
				this.choose_id = id;
			},
			on_confirm: function() {
				uni.showModal({
					content: '确定选择该疆域吗？',
					success: (r) => {
						if (r.confirm) {
							let data = {
								area_type: this.list[this.choose_id].area_type
							}
							this.$api.chooseArea(data, res => {
								if (res.status) {
									this.$common.successToShow(res.msg)
									uni.navigateBack()
									this.$refs.choose_area.close();
								} else {
									this.$common.errorToShow(res.msg)
								}
							})
						}
					}
				});
			}

		}
	}
</script>

<style lang="scss">
	.confirm_btn {
		width: 490rpx;
		height: 90rpx;
		background: #FF0000;
		border-radius: 10rpx;
		margin: 75rpx 17rpx 0;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 32rpx;
		font-weight: bold;
		color: #FFFFFF;
	}

	.area_box {
		width: 524rpx;
		height: 305rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 40rpx 30rpx 75rpx;
		font-size: 32rpx;
		color: #000000;

		.area_list {
			width: 100%;
			padding-top: 40rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.area_item {
				width: 106rpx;
				height: 106rpx;
				background: #BCBCBC;
				border-radius: 10rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				view {
					font-style: oblique;
					font-weight: bold;
					color: #787878;
					font-size: 60rpx;
					transform: translateX(-5rpx)
				}
			}

			.area_on {
				background-color: #f00;

				view {
					color: #fff;
				}
			}
		}
	}

	.none_box {
		width: 100%;
		display: flex;
		align-items: center;
		flex-direction: column;
		padding: 260rpx 0;

		.none_img {
			width: 280rpx;
			height: 253rpx;
			margin-bottom: 36rpx;
		}

		.none_text {
			font-size: 28rpx;
			color: #9CA7B7;
		}
	}
</style>
